%% Author: Administrator
%% Created: Aug 25, 2006
%% Description: TODO: Add desciption to aleph_config
-module(aleph_config).
-include("aleph_naming_macros.hrl").
-include("aleph_service_macros.hrl").
-behaviour(gen_server).
%%
%% Exported Functions
%%
-export([format_system/0,get_logger_dir/0,get_logger_max_size/0,
         get_logger_buffer_delay/0,get_reply_time_out/0,
         get_db_options/0,get_dump_db_interval/0]).

-export([handle_call/3,handle_info/2,terminate/2,handle_cast/2,         
        init/1,start_link/0,start/0,process_spec/0]).

-import(aleph_process_labeler,[label_process/1]).
%%%%%%%%%%%%%behaviour implementations
start_link() ->
   start_config(start_link).

start()-> 
   start_config(start).

start_config(Start)->     
     label_process(
                  gen_server:Start({local,?CONFIG_PROCESS},aleph_config, [], [])).
%%%%%%%%%%%%%callback implementations
init([]) ->
    process_flag(trap_exit, true),
    {ok,ok}. 

-define(SERVICE_NAME,?CONFIG_PROCESS).
?gen_handle_call.
?gen_handle_cast.  
?gen_handle_info.    

terminate(Reason,_)->  
    io:format("~p closed because of ~p~n",[?CONFIG_PROCESS,Reason]),
    ok.     
%%
%% Static API Functions
%%
format_system()->   
    purge_persistent_data(),
    intial_config().  
    

process_spec()->
    {?CONFIG_PROCESS,{aleph_config,start_link,[]},transient, brutal_kill,worker, [aleph_config]}.
    
get_logger_dir()->
    "c:\\Aleph\\Logs".
get_logger_max_size()->
    1024*1024.
get_logger_buffer_delay()->
    2000.
get_reply_time_out()->
    5000.
get_db_options()->
   [{disc_copies, nodes()}, {type,bag}].
get_dump_db_interval()->
    3000.

%%
%% Local Functions
%%
intial_config()->    
   ok.
purge_persistent_data()->
    lists:foreach(fun(T)->
        try
        mnesia:delete_table(T)       
        catch
        exit:_->ok;
        error:_->ok
        end end,?PERSISTENT_TABS).